package com.tanhua.server.controller;

import com.tanhua.dubbo.api.UserApi;
import com.tanhua.server.service.UserService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class LoginController {

    @Autowired
    private UserService userService;

    @DubboReference
    private UserApi userApi;

    /**
     * 发送验证码
     */
    @PostMapping("/login")
    public ResponseEntity login(@RequestBody Map map){
        String phone = (String) map.get("phone");

        userService.sendSms(phone);

        return ResponseEntity.ok(null);
    }

    /**
     * 用户登录--验证码校验
     * @param map
     * @return
     */
    @PostMapping("/loginVerification")
    public ResponseEntity loginVerification (@RequestBody Map map){
        String phone = (String) map.get("phone");
        String code = (String) map.get("verificationCode");

        Map resMap = userService.loginVerification(phone,code);

        return ResponseEntity.ok(resMap);
    }
}
